package com.xxxcompany.blog.dao.impl;


import java.sql.*;

import com.xxxcompany.blog.dao.IUserDAO;
import com.xxxcompany.blog.entity.User;
import com.xxxcompany.utils.DbUtils;

public class UserDAOImpl implements IUserDAO{

	@Override
	public int insert(User user) throws SQLException 
	{
		// 1. 获取连接
		Connection conn = DbUtils.getConnection();
		
		// 2. 得到Statement
		String sql = "insert into user(id,username,password,email,nickname) value(null,?,?,?,?)";
		PreparedStatement pstmt = conn.prepareStatement(sql);
		pstmt.setString(1, user.getUsername());
		pstmt.setString(2, user.getPassword());
		pstmt.setString(3, user.getEmail());
		pstmt.setString(4, user.getNickname());
		int result = pstmt.executeUpdate();
		
		
		// 3. 释放资源
		DbUtils.destoryResource(conn, pstmt, null);
		
		return result;
	}

}
